USE ConsultTracking
go
drop proc CreateContact
drop proc UpdateContact
GO
-------------------------------------------------
create proc CreateContact
@FirstName nvarchar(50),
@LastName nvarchar(50),
@OfficePhone nvarchar(50) = '',
@MobilePhone nvarchar(50) = '',
@Email nvarchar(100) = '',
@WorkLocationID int,
@CustomerID int,
@PurposeTypeID int,
@PurposeDescription nvarchar(200) = ''
as
INSERT INTO [ConsultTracking].[dbo].[Contact]
           ([FirstName]
           ,[LastName]
           ,[OfficePhone]
           ,[MobilePhone]
           ,[Email]
           ,[WorkLocationID]
           ,[CustomerID])
     VALUES
           (@FirstName
           ,@LastName
           ,@OfficePhone
           ,@MobilePhone
           ,@Email
           ,@WorkLocationID
           ,@CustomerID)

declare @LastContactID int
set @LastContactID = (select max(ContactID) from Contact)

INSERT INTO [ConsultTracking].[dbo].[ContactPurpose]
           ([ContactID]
           ,[PurposeTypeID]
           ,[Description])
     VALUES
           (@LastContactID
           ,@PurposeTypeID
           ,@PurposeDescription)
------------------------------------------------------------
go
create proc UpdateContact
@ContactID int,
@FirstName nvarchar(50),
@LastName nvarchar(50),
@OfficePhone nvarchar(50),
@MobilePhone nvarchar(50),
@Email nvarchar(100),
@WorkLocationID int
as
UPDATE [ConsultTracking].[dbo].[Contact]
   SET [FirstName] = @FirstName
      ,[LastName] = @LastName
      ,[OfficePhone] = @OfficePhone
      ,[MobilePhone] = @MobilePhone
      ,[Email] = @Email
      ,[WorkLocationID] = @WorkLocationID
	  ,[Modified] = GETDATE()
 WHERE ContactID = @ContactID